﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using SiteUnity.Layers.Application;
using SiteUnity.Layers.Application.BaseClasses;

namespace SiteUnity.Frame.Modules
{
    [ToolboxData("<{0}:FacebookButton runat=server />")]
    public class FacebookButton : BaseWebControl
    {
        public string ColorScheme { get; set; }
        public bool Send { get; set; }

        public FacebookButton()
        {
            Send = false;
        }

        string _template = @"<div id='fb-root'></div>     
            <script>
                FB.init({
                    appId: '172450632810886',
                    status: true, // check login status
                    cookie: true, // enable cookies to allow the server to access the session
                    xfbml: true  // parse XFBML
                });
            </script>
            <fb:like href='{0}'
                send='{2}' width='110' layout='button_count' show_faces='false' colorscheme='{1}' font=''>
            </fb:like>";
        protected override void OnPreRender(EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptInclude(typeof(Page), "fbready", "http://connect.facebook.net/en_US/all.js");
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write(_template
                .Replace("{0}", SiteManager.Website.Url + SiteManager.Website.CurrentPage.Url)
                .Replace("{1}",ColorScheme)
                .Replace("{2}",Send.ToString().ToLower()));
        }
    }
}
